package com.hyb.algorithm.data.struct.other;

/**
 * @author: ybhu
 * @create: 2021/09/19 20:39
 *
 * 11. 盛最多水的容器
 *
 * https://leetcode-cn.com/problems/container-with-most-water/
 */
public class MaxArea {


    //  area=(j-i)*Math.min(h1,h2);
    public int maxArea(int[] height) {
        int n=height.length;
        int maxArea=0;
        int i=0;
        int j=n-1;
        while(i<j){

            int area=(j-i)*Math.min(height[i],height[j]);
            maxArea=Math.max(area,maxArea);

            if(height[i]<=height[j]){
                i++;
            }else{
                j--;
            }
        }
        return maxArea;
    }



    //  area=(j-i)*Math.min(h1,h2);  暴力解法
    public int maxArea1(int[] height) {
        int n=height.length;
        int maxArea=0;
        //暴力解法
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                int area=(j-i)*Math.min(height[i],height[j]);
                maxArea=Math.max(area,maxArea);
            }
        }
        return maxArea;
    }
}
